package com.example.administrator.xjscc;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity implements View.OnClickListener{
    private Button bt_viewWork,bt_roadStatus,bt_viewWeather,bt_rescue,bt_mileage;
    private Button bt_monirescue;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bt_viewWork=(Button)findViewById(R.id.bt_viewWork);
        bt_roadStatus=(Button)findViewById(R.id.bt_roadStatus);
        bt_viewWeather=(Button)findViewById(R.id.bt_viewWeather);
        bt_rescue=(Button)findViewById(R.id.bt_rescue);
        bt_mileage=(Button)findViewById(R.id.bt_mileage);
        bt_monirescue=(Button)findViewById(R.id.bt_monirescue);

        bt_viewWork.setOnClickListener(this);
        bt_roadStatus.setOnClickListener(this);
        bt_viewWeather.setOnClickListener(this);
        bt_rescue.setOnClickListener(this);
        bt_mileage.setOnClickListener(this);
        bt_monirescue.setOnClickListener(this);

    }
    @Override
    public void onClick(View view) {
        Intent i=new Intent();
        switch (view.getId())
        {
            case R.id.bt_viewWork:
                i.setClass(MainActivity.this,ViewWorkActivity.class);
                startActivity(i);
                break;
            case R.id.bt_roadStatus:
                i.setClass(MainActivity.this,RoadStatusActivity.class);
                startActivity(i);
                break;
            case R.id.bt_viewWeather:
                i.setClass(MainActivity.this,WeatherActivity.class);
                startActivity(i);
                break;
            case R.id.bt_rescue:
                i.setClass(MainActivity.this,RescueActivity.class);
                startActivity(i);
                break;
            case R.id.bt_mileage:
                i.setClass(MainActivity.this,MileGatherActivity.class);
                startActivity(i);
                break;
            case R.id.bt_monirescue:
                SendNotification();
                break;
        }
    }
    private void SendNotification()
    {
        NotificationManager nm=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE);
        Intent i=new Intent(MainActivity.this,RescueActivity.class);
        PendingIntent pendingIntent3 = PendingIntent.getActivity(this, 0,i, 0);

        Notification notify3 = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setTicker("故障紧急救援")
                .setContentTitle("紧急救援")
                .setContentText("救援信息")
                .setContentIntent(pendingIntent3).setNumber(1).build(); // 需要注意build()是在API
        notify3.defaults=Notification.DEFAULT_ALL;
        notify3.flags |= Notification.FLAG_AUTO_CANCEL;
        nm.notify(0, notify3);
    }
}
